package org.lsj.kit.config.listener;

import org.lsj.kit.config.ConfigAttributeCache;
import org.lsj.kit.mapper.MenuResourceMapper;
import org.lsj.kit.mapper.RoleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

/**
 * Created by lishengjie on 2019/3/4.
 *
 * 需要监听特定的事件，否则这个方法会被执行很多次ApplicationListener启动时执行多次
 */
@Component
public class ConfigAttributeCacheListener implements ApplicationListener<ContextRefreshedEvent>{
    @Autowired
    private MenuResourceMapper resourceMapper;
    @Autowired
    private RoleMapper roleMapper;
    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        ConfigAttributeCache.refreshCache(resourceMapper,roleMapper);
    }
}
